# -*- coding: utf-8 -*-
from src.game.entity.entity import Entity
from src.game.entity.living import EntityLiving
from src.game.entity.knight import EntityKnight
from src.handler.sprite import SpriteHandler
import pygame, pymunk


class EntityStone(Entity):

    name = "entitystone"

    def __init__(self):
        Entity.__init__(self)
        self.width = 0.5
        self.height = 0.5
        self.mass = pymunk.inf
        self.collision = True

    def onClick(self, x, y):
        pass

    def onCollision(self, entity):
        if isinstance(entity, EntityLiving):
            entity.damage(1, EntityStone.name, 1)


    def render(self, client, viewport):
        Entity.render(self, client, viewport)
        localX, localY = viewport.globalToLocale(self.x, self.y)
        sprite = SpriteHandler.get("stone")

        client.window.surface.blit(sprite, (localX * 64, localY * 64))
        
class EntitySpawner(Entity):
    
    name = "entityspawner"
    
    def __init__(self):
        Entity.__init__(self)
        self.width = 1
        self.height = 1
        self.mass = pymunk.inf
        self.collision = False
        
    def onClick(self, x, y):
        entity = EntityKnight()
        entity.x = x
        entity.y = y
        self.world.spawnEntity(entity)
        
    def render(self, client, viewport):
        Entity.render(self, client, viewport)
        localX, localY = viewport.globalToLocale(self.x, self.y)
        sprite = SpriteHandler.get("spawner")

        client.window.surface.blit(sprite, (localX * 64, localY * 64))
